package com.example.mongodb.mongodb;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : zhayh
 * @date : 2021-5-16 21:04
 * @description : 中文分词工具类
 */

public class IkTools {
    public static List<String> keywords(String text) throws IOException {
        StringReader strReader = new StringReader(text);
        IKSegmenter ik = new IKSegmenter(strReader, true);
        List<String> list = new ArrayList<>();
        Lexeme lex = null;
        while ((lex = ik.next()) != null) {
            list.add(lex.getLexemeText());
        }
        return list;
    }
}
